package com.muke.spring.demo1;

import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

/**
* Created By lijiliang on 2018年7月16日 下午10:30:36
*/
public class AccountServiceImpl implements AccountService {
	private AccountDao accountDao;
	
	
	


	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}


	//注入事务管理的模板
	private TransactionTemplate transactionTemplate;
	

	public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
		this.transactionTemplate = transactionTemplate;
	}


	@Override
	public void transfer(String out, String in, Double money) {
		transactionTemplate.execute(new TransactionCallbackWithoutResult() {
			
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) {
				accountDao.outMoney(out, money);
				int i=2/0;
				accountDao.inMoney(in, money);
			}
		});
	}

}
